import sys

from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QLineEdit, QPushButton, QFrame, QVBoxLayout, QHBoxLayout

'''
单行文本编辑框及文本改变事件TextChange
QT信号槽调用机制connect(self.ljyTxt)
文本标签宽度自适应 adjustSize()  # 使默认固定宽度改变为自适应
'''


class MyClass(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle('刘金玉编程')
        self.setGeometry(800, 370, 400, 300)

        self.lbl = QLabel('显示区', self)
        self.lbl.move(10, 50)

        self.le = QLineEdit(self)
        self.le.move(10, 20)
        self.le.textChanged[str].connect(self.ljyTxt)  # 信号传参数要把小括号改为中括号,里面指定 类型str

        self.show()

    def ljyTxt(self, s):
        self.lbl.setText(s)
        self.lbl.adjustSize()  # 使默认固定宽度改变为自适应


if __name__ == '__main__':
    app = QApplication(sys.argv)
    myf = MyClass()
    app.exec_()
